package com.guiji.text2video.fastvideo.config;

import com.guiji.text2video.fastvideo.domain.vo.NewsCategoryPriority;
import com.guiji.text2video.fastvideo.utils.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Copyright (C), 2018-2021
 * FileName: NewsCategoryConfig
 * Author:   scl
 * Date:     2021/7/23 10:49
 * Description: 新闻优先级配置类
 */
@Configuration
public class NewsCategoryConfig {

    @Value("${file-cache.composeVideo-news-url}")
    private String composeVideoNewsUrl;

    private List<String> urlList;

    private int auto = 1;


    public List<String> getUrlList() {
        //保证只被执行一次
        synchronized (this) {
            if (auto == 1 && ObjectUtils.isEmpty(urlList)) {
                setUrlList();
                auto++;
            }
        }
        return urlList;
    }

    public void setUrlList() {
        System.out.println("setUrlList初始化");
        //线程共享集合，读效率大于写效率
        this.urlList = new CopyOnWriteArrayList<>();
        if (composeVideoNewsUrl.contains(",")) {
            String[] stirs = composeVideoNewsUrl.split(",");
            for (String str : stirs) {
                this.urlList.add(str);
            }
        } else {
            this.urlList.add(composeVideoNewsUrl);
        }
    }
}